<?php

tsLoad('/core/CoreLib/AbstractMysqlPage.class.php');
class SysProfitPage extends AbstractMysqlPage {
	/*
	 * 取得总的行数
	 */
	protected function calTotalRows (){
		global $mysqlTools;
        $condition = $mysqlTools->check_input($this->condition,array('userLoginId'));
        //$userId =$userSession->getUserSession()["userId"];
       	$sqlCore = "
       		select count(*) as totalCount from sys_profit_info sp	
        ";
        $where = "
         	WHERE 1=1 
        ";
        //查看状态
        if(!empty($condition['sysProInReason']) && $condition['sysProInReason']!=5){
        	$where.= ' AND sp.sysProInReason ='.$condition['sysProInReason'];
        }
        
	 	//创建开始时间与结束时间
        if(!empty($condition['withdCreatetimeStart'])){
        	$where.= ' AND sp.sysProInCreatetime >='.$condition['withdCreatetimeStart'];
        }
        if(!empty($condition['withdCreatetimeEnd'])){
        	$where.= ' AND sp.sysProInCreatetime <='.$condition['withdCreatetimeEnd'];
        }
        
        $sql = $sqlCore.$where;
        //总记录数
        $totalRows = $mysqlTools->selectSql($sql)[0]['totalCount'];
        
        return $totalRows;
	}
	
	/*
	*取得数据集合
			*/
	protected function getList ($sRowNo, $pageRows)
	{
	    global $mysqlTools;
	  	$condition = $mysqlTools->check_input($this->condition,array('userLoginId'));
        //保存一个原生值以便需要的时候进行处理
        $orgCondition = $this->condition;
        $sqlCore = "
				    select 
					   sysProInId,
					   sysProInCreatetime,
					   sysProInReason,
					   sysProInMo
					from 
					sys_profit_info sp
        ";
        
        $where = "
         	WHERE 1=1 
        ";
        //查看状态
        if(!empty($condition['sysProInReason']) && $condition['sysProInReason']!=5){
        	$where.= ' AND sp.sysProInReason ='.$condition['sysProInReason'];
        }
        
	 	//创建开始时间与结束时间
        if(!empty($condition['withdCreatetimeStart'])){
        	$where.= ' AND sp.sysProInCreatetime >='.$condition['withdCreatetimeStart'];
        }
        if(!empty($condition['withdCreatetimeEnd'])){
        	$where.= ' AND sp.sysProInCreatetime <='.$condition['withdCreatetimeEnd'];
        }
        
        $order = " ORDER BY sp.sysProInCreatetime DESC ";
        
        $limit = " LIMIT $sRowNo,$pageRows";
        
        $sql = $sqlCore.$where.$order.$limit;
        
        //查询角色信息分页
        $list = $mysqlTools->selectSql($sql);
        
        return $list;
	}
	
	public function queryGlobalMo($condition){
		global $mysqlTools;
		$condition = $mysqlTools->check_input($condition,array('userLoginId'));
		//保存一个原生值以便需要的时候进行处理
		$orgCondition = $this->condition;
		$sqlCore = "
				    select
						sum(sp.sysProInMo) moneySum
					from
					sys_profit_info sp
        ";
		$where = "
         	WHERE 1=1
        ";
		//查看状态
		if(!empty($condition['sysProInReason']) && $condition['sysProInReason']!=5){
			$where.= ' AND sp.sysProInReason ='.$condition['sysProInReason'];
		}
		
		//创建开始时间与结束时间
		if(!empty($condition['withdCreatetimeStart'])){
			$where.= ' AND sp.sysProInCreatetime >='.$condition['withdCreatetimeStart'];
		}
		if(!empty($condition['withdCreatetimeEnd'])){
			$where.= ' AND sp.sysProInCreatetime <='.$condition['withdCreatetimeEnd'];
		}
		$list = $mysqlTools->selectSql ( $sqlCore.$where );
		if (is_array ( $list ) && ! empty ( $list ))
			return $list[0];
		else
			return array();
	}
	
	public function queryBalanceOfPaymentsDetails($param){
		global $mysqlTools;
		if(!isset($param["sysProInId"]) || empty($param["sysProInId"])){
			$param["sysProInId"] = -1;
		}
		$condition = $mysqlTools->check_input($param);
		//保存一个原生值以便需要的时候进行处理
		$sql = "
			SELECT
				ubi.userInFZf,
				ubi.userInFLoginId,
				ubi.userInFCreatetime,
				ubi.userInFType,
				ubi.userInFMo,
				sr.roleDesc,
				ubi.userInFReason,
				ubi.userInFSurGlod,
				ubi.sysProInId
			FROM
				user_bop_info AS ubi
			LEFT JOIN sys_role sr ON ubi.roleId = sr.roleId
			WHERE ubi.sysProInId = $param[sysProInId]
        ";
		$list = $mysqlTools->selectSql ( $sql );
		if (is_array ( $list ) && ! empty ( $list ))
			return $list;
		else
			return array ();
	}
}
?>